package io.renren.modules.sys.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.modules.sys.entity.SongEntity;
import io.renren.modules.sys.entity.SongRecommendEntity;
import io.renren.modules.sys.service.SongService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.SongNewEntity;
import io.renren.modules.sys.service.SongNewService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author wangyi
 * @email 794651397@qq.com
 * @date 2018-02-24 10:46:32
 */
@RestController
@RequestMapping("/sys/songnew")
public class SongNewController {
	@Autowired
	private SongNewService songNewService;

    @Autowired
    private SongService songService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<SongEntity> songRecommendList = songNewService.queryList(query);
        int total = songNewService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(songRecommendList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id){
		SongNewEntity songNew = songNewService.queryObject(id);
		
		return R.ok().put("songNew", songNew);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody SongNewEntity songNew){
		songNewService.save(songNew);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody SongNewEntity songNew){
		songNewService.update(songNew);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids){
		songNewService.deleteBatch(ids);
		
		return R.ok();
	}

    /**
     * 列表
     */
    @RequestMapping("/listAll")
    public R listAll(@RequestParam Map<String, Object> params){
        List<SongEntity> songRecommendList = songNewService.queryListAll(params);

        return R.ok().put("list", songRecommendList);
    }

    /**
     * 配置
     */
    @RequestMapping("/checkSong")
    public R checkSong(@RequestBody List<SongNewEntity> sList){
        songNewService.deleteAll();
        for (SongNewEntity songNewEntity : sList) {
            songNewEntity.setCreateTime(new Date());
        }
        songNewService.insertBatch(sList);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/newList")
    public R recommendList(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<SongEntity> songList = songService.queryListNewSort(query);
        int total = songService.queryTotalNewSort(query);

        PageUtils pageUtil = new PageUtils(songList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
}
